package cn.hs.ph.dao.impl;

import cn.hs.ph.dao.UserDao;
import cn.hs.ph.entity.User;
import cn.hs.ph.util.JDBCDruidUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    @Override
    public User selectByUsernameAndPwd(String username, String pwd) {
        String sql = "select * from user where username=? and password=?";
        Object[] obj = {username, pwd};
        User user = null;
        ResultSet res = JDBCDruidUtil.query(sql, obj);
        try {
            if (res.next()) {
                user = new User(res.getInt(1), username, pwd);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return user;
    }
}
